package com.hxc.common.utils;

import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GeodeticCurve;
import org.gavaghan.geodesy.GlobalCoordinates;

/**
 * 功能描述: 坐标距离计算
 * @author yzj
 */
public class DistanceUtils {

    public static Boolean querySpace(String sourceX, String sourceY, String targetX, String targetY, Integer spaceNum){
        //当前坐标
        GlobalCoordinates source = new GlobalCoordinates(Double.valueOf(sourceX),Double.valueOf(spaceNum));
        //目的坐标
        GlobalCoordinates target = new GlobalCoordinates(Double.valueOf(targetX),Double.valueOf(targetY));
        //2点间距
        Double spacingNum = getDistanceMeter(source, target, Ellipsoid.WGS84);
        if(spacingNum > spaceNum){
            return false;
        }else{
            return true;
        }
    }

    private static Double getDistanceMeter(GlobalCoordinates gpsFrom, GlobalCoordinates gpsTo, Ellipsoid ellipsoid){
        //创建GeodeticCalculator，调用计算方法，传入坐标系、经纬度用于计算距离
        GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(ellipsoid, gpsFrom, gpsTo);
        return geoCurve.getEllipsoidalDistance();
    }

}
